//
//  SetGestureLockViewController.m
//  DaDaBao
//
//  Created by user on 15/8/19.
//  Copyright (c) 2015年 User. All rights reserved.
//
#import "TotalViewController.h"
#import "SetGestureLockViewController.h"

@interface SetGestureLockViewController ()<yyGestureDelegate>
@property (nonatomic,strong)YYGestureLockView * gestureLockView;
@property (nonatomic,unsafe_unretained)GestureLockType gestureType;
@property (nonatomic, strong) UIButton * forgotPsdBtn;//密码登录按钮
@end

@implementation SetGestureLockViewController
-(id)initWithGestureType:(GestureLockType)getstureType
{
    if (self = [super init])
    {
        _gestureType = getstureType;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = RGBA(26, 34, 45, 1);
    if (_gestureType == verifyGestureLock)
    {
        [[UIApplication sharedApplication]setStatusBarHidden:FALSE];
        [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
        _gestureLockView = [[YYGestureLockView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) andGestureType:_gestureType];
        
        _forgotPsdBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _forgotPsdBtn.frame = CGRectMake(0, 0, 100, 44);
        _forgotPsdBtn.center = CGPointMake(self.view.center.x, _gestureLockView.frame.size.height - 40);
        [_forgotPsdBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_forgotPsdBtn addTarget:self action:@selector(buttonSelectLoginTypeTapped:) forControlEvents:UIControlEventTouchUpInside];
        [_forgotPsdBtn setTitle:@"忘记密码？" forState:UIControlStateNormal];
        [_gestureLockView addSubview:_forgotPsdBtn];
        
    }else
    {
     [self createTheNavigationBar];
     _gestureLockView = [[YYGestureLockView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT -64) andGestureType:_gestureType];
    }
     _gestureLockView.yyGestureDelegate = self;
    [self.view addSubview:_gestureLockView];
}
#pragma mark -忘记密码
-(void)buttonSelectLoginTypeTapped:(id)sender
{
    //点击的时候，让退出登录，同时
    [AppGlobalClass exitLogin];
    [[[[[UIApplication sharedApplication] delegate] window] rootViewController]dismissViewControllerAnimated:FALSE completion:nil];
    [_delegate enterTotal];
}
#pragma mark ------------创建导航栏
-(void)createTheNavigationBar
{
    [[UIApplication sharedApplication]setStatusBarHidden:FALSE];
    [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
    
    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, SCREEN_WIDTH, 64.0f)];
    topView.backgroundColor = [UIColor hexStringToColor:COLOR_VALUE];
    [self.view addSubview:topView];
    //标题
    UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0.0f, 20.0f, SCREEN_WIDTH, 44.0f)];
    titleLab.backgroundColor = [UIColor clearColor];
    titleLab.font = [UIFont boldSystemFontOfSize:20.0f];
    titleLab.textColor = [UIColor whiteColor];
    titleLab.text = @"设置手势密码";
    titleLab.textAlignment = NSTextAlignmentCenter;
    [topView addSubview:titleLab];
    
    //返回按钮
    UIButton *backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0.0f, 20.0f, 64.0f, 44.0f)];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(buttonBackTapped:) forControlEvents:UIControlEventTouchUpInside];
    [topView addSubview:backBtn];
    
}
#pragma mark-返回方法
-(void)buttonBackTapped:(id)sender
{
     [_delegate enterTotal];
    [self.navigationController popViewControllerAnimated:TRUE];
    [[[[[UIApplication sharedApplication] delegate] window] rootViewController]dismissViewControllerAnimated:TRUE completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark------------gestureSuccessDelegate
-(void)gestureSuccess
{
    [self buttonBackTapped:nil];
}
-(void)gestureFailed
{
    
    //退出登录
    [AppGlobalClass exitLogin];
    [[[[[UIApplication sharedApplication] delegate] window] rootViewController]dismissViewControllerAnimated:TRUE completion:nil];
    
    if (_gestureType == reSetGestureLock)
    {
        TotalViewController *totalViewCon = [[TotalViewController alloc]init];
        [self.navigationController pushViewController:totalViewCon animated:FALSE];
    }else
    {
        [_delegate enterTotal];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
